<?php

namespace App\Model;

use App\Comment\Comment;
use Illuminate\Database\Eloquent\Model;

class SysUser extends Model
{
    protected $table = 'sys_user';


    /**
     * 后台管理员员登录功能
     * @param $data 需要校验的用户名和密码
     * @return bool
     */
    public function sysUserLogin($data)
    {
        if (!is_array($data)){
            return false;
        }
        $info = SysUser::where(['username' => $data['admin_name']]) -> first();
        if (!$info){
            return false;
        }
        if (Comment::member_md5($data['admin_pwd'],config('params.password_key')) === $info -> password){
            session(['admin' => ['id' => $info -> id, 'name' => $info -> username]]);
            return true;
        }
        return false;
    }
}
